const express = require('express')

const app = express()

const expressSwagger = require('express-swagger-generator')(app)

let options = {
  swaggerDefinition: {
    info: {
      description: '这是王者荣耀后台管理系统的api文档，<h2>前端： vue + axios + element ui </h2><h2>后端： .net core web api + mongoDb + open API + JsonWebToken </h2><h3>项目虽然不是很牛逼，但是还不错，够骚气，如果你想获得足够的力量，却什么都不会，没有关系，b站 https://space.bilibili.com/341919508，如果你喜欢前端，node，nest，.net core,来吧老弟，一起加油，一起学习，奥利给！！</h3>',
      title: "王者荣耀官网后台管理 --api文档",
      version: '1.0.0',
      termsOfService: "http://swagger.io/terms/",
      contact: {
        email: "1409458062@qq.com"
      },
      license: {
        name: "Apache 2.0",
        url: "http://www.apache.org/licenses/LICENSE-2.0.html"
      }
    },
    host: 'localhost:3000',
    basePath: '/admin/api/rest',
    produces: [
      "application/json",
      "application/xml"
    ],
    schemes: ['http', 'https'],
    securityDefinitions: {
      JWT: {
        type: 'apiKey',
        in: 'header',
        name: 'Authorization',
        description: "获取登录凭证",
      }
    }
  },
  basedir: __dirname, //app absolute path
  files: ['./routers/**/*.js'] //Path to the API handle folder
};

expressSwagger(options)

app.set('secret', 'asdasdasdasdasd')

app.use(require('cors')())
app.use(express.json())
app.use('/admin', express.static(__dirname + '/admin'))
app.use('/', express.static(__dirname + '/web'))
app.use('/uploads', express.static(__dirname + '/uploads'))

require('./plugins/db')(app)

require('./routers/admin')(app)
require('./routers/web')(app)

app.listen(3000, () => {
  console.log('ok')
})